﻿Imports ExceptionHandling

Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Public ReadOnly Property OptIn() As Boolean
            Get
                Return My.Settings.OptIn
            End Get
        End Property

        Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

        End Sub

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

            UnhandledExceptionManager.AddHandler()
            UnhandledExceptionManager.IgnoreDebugErrors = True
            If My.Settings.ErrorReporting = True Then
                UnhandledExceptionManager.SendEmail = True
                UnhandledExceptionManager.MailAddress = "support+meamodplayme@meamod.com"
            ElseIf My.Settings.ErrorReporting = False Then
                UnhandledExceptionManager.SendEmail = False
                UnhandledExceptionManager.MailAddress = "null@localhost.null"
            End If
            UnhandledExceptionManager.LogToFile = True
            UnhandledExceptionManager.LogToEventLog = True
            UnhandledExceptionManager.TakeScreenshot = False
            UnhandledExceptionManager.DisplayDialog = True
            UnhandledExceptionManager.EmailScreenshot = False
            UnhandledExceptionManager.KillAppOnException = True
            UnhandledExceptionManager.ContactInfo = "MeaMod Support at support@meamod.com"
            Dim userFilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\" + My.Application.Info.CompanyName + "\" + My.Application.Info.AssemblyName
            Dim fileExistsVLC As Boolean
            fileExistsVLC = My.Computer.FileSystem.FileExists(userFilePath + "\OCDS.cfg")
            If fileExistsVLC = False Then
                My.Computer.FileSystem.CreateDirectory(userFilePath)
                My.Computer.FileSystem.WriteAllText(userFilePath + "\OCDS.cfg", String.Empty, False)
            End If

        End Sub

        Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
            Dim inputArgument As String = ""
            Dim inputName As String = ""
            For Each s As String In e.CommandLine
                If s.ToLower.StartsWith(inputArgument) Then
                    inputName = s.Remove(0, inputArgument.Length)
                End If
            Next
            If inputName = "" Then
            Else
                frmMain.OpnFile(inputName)
            End If
        End Sub
    End Class

End Namespace

